package com.ccp.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
 * @author Cony
 *
 */
public class BaseAction extends ActionSupport {
	
	private static final long serialVersionUID = -7509152655359967096L;


	/**
	 * @param key
	 * @return
	 */
	protected boolean isExistSession(String key) {
		if (ActionContext.getContext().getSession().get(key) != null) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * @param key
	 * @param obj
	 */
	protected void setSession(String key, Object obj) {
		ActionContext.getContext().getSession().put(key, obj);
	}

	/**
	 * @param key
	 * @return
	 */
	protected Object getSession(String key) {
		return ActionContext.getContext().getSession().get(key);
	}
	
	
	/**
	 * @return
	 */
	protected HttpServletRequest getRequest() {
		return ServletActionContext.getRequest();
	}
	
	/**
	 * @return
	 */
	protected HttpServletResponse getRespose() {
		return ServletActionContext.getResponse();
	}
	
	/**
	 * @param key
	 */
	protected void saveActionError(String key) {
		super.addActionError(super.getText(key));
	}
	
	/**
	 * @param key
	 */
	protected void saveActionMessage(String key) {
		super.addActionMessage(super.getText(key));
	}
	
	/**
	 * @return
	 */
	protected String getRequestPath() {
		return (String)ServletActionContext.getRequest().getServletPath();
	}
	
}
